#!/usr/bin/node

const EventEmitter = require('events');

function Dog(name,enery){
  let _name = name,
      _enery = enery,
      that = this;

  EventEmitter.call(this);

  let timer = setInterval(()=>{
    if(_enery > 0){
      that.emit('bark');
      _enery--;
    }else{
      clearInterval(timer);
    }
    
  },1000);

  this.name = ()=>_name;
  this.enery =()=>_enery;
}

Dog.prototype = EventEmitter.prototype;

module.exports = Dog;
